package A1动态规划;

public class LC_53最大子数组和 {
    public static void main(String[] args){
        int[] nums={-2,1,-3,4,-1,2,1,-5,4};
        System.out.println(maxSubArray(nums));
    }
    public static int maxSubArray(int[] nums) {
        if(nums.length==0||nums==null)
            return 0;
        int[] dp=new int[nums.length];
        dp[0]=nums[0];
        int res=nums[0];
        for(int i=1;i<nums.length;i++){
            dp[i]=Math.max(nums[i],dp[i-1]+nums[i]);
            if(dp[i]>res)
                res=dp[i];
        }
        return res;
    }
}
